import $ from '../../../utils/ajax.js';
import util from '../../../utils/util.js';
const app = getApp();
Page({
    data: {
        xfjArr: ['', '幸福纪省级运营服务商合作协议', '幸福纪城市运营服务商合作协议'],
        xfjPdf: ['',
            'https://xfj.oss-cn-shanghai.aliyuncs.com/protocol/shengjidaili_protocol.pdf',
            'https://xfj.oss-cn-shanghai.aliyuncs.com/protocol/shijidaili_protocol.pdf'
        ],
        items: [
            { name: 1, value: '省级运营服务商' },
            { name: 2, value: '城市运营服务商' }
        ],
        agentInt: 1,
        protocol: false,
        agreement: '协议下载中',
        second: 0,
    },
    onLoad(options) {
        this.setData({
            second: Number(options.second)
        })
    },
    protocolBtn() {
        /**
         * 勾选协议
         */
        this.setData({
            protocol: !this.data.protocol,
        })
    },
    bindPickerChange(e) {
        /**
         * 选择运营商
         */
        this.setData({
            agentInt: Number(e.detail.value),
            protocol: false,
        })
    },
    onPdf() {
        wx.showLoading({
            mask: true,
            title: this.data.agreement
        })
        wx.downloadFile({
            url: this.data.xfjPdf[this.data.agentInt],
            success: function (res) {
                console.log(res)
                const filePath = res.tempFilePath;
                setTimeout(() => {
                    wx.openDocument({
                        filePath: filePath,
                        fileType: 'pdf',
                        success: function (res) {
                            console.log(res)
                        }
                    })
                },100);
                wx.hideLoading();
            }
        })
    },
    onOk() {
        const second = this.data.second
        if (util.nonCompare(!this.data.protocol, '请勾选协议')){
            if (second === 100) {
                const item = {
                    role: this.data.agentInt
                }
                wx.navigateTo({
                    url: '/pages/examine/collective/collective?second=100&item=' + JSON.stringify(item)
                })
            } else {
                $.p(app.wxApp.url + 'agentnew/saveAgentType', {
                    role: this.data.agentInt,
                    tel: wx.getStorageSync('tel'),
                    agent: wx.getStorageSync('agent'),
                }, app.onStrart, (res) => {
                    app.agentStatus();
                }, (res) => {
                    util.showToast(res.data)
                })
            }
        }
    }


})